import { httpGet } from "/utils/request.js"

export const listCopy = (toList, copiedList) => {
	toList.length = 0
	toList.push(...copiedList)
}

export const blurQuery = (_to_query, _shop_data, _dish_data, _shop_dish) => {
	let result = []
	// 匹配 店铺名 | 菜名
	function get_similars(_to_query, _data) {
		for (const item of _data) {
			const keys = Object.keys(item)
			for (let i in keys) {
				const matched = item[keys[i]]
				if (typeof(matched) == 'string' && matched.toLowerCase().includes(_to_query)) {
					result.push(item)
				}
			}
		}
	}
	get_similars(_to_query, _shop_data)
	get_similars(_to_query, _dish_data)
	// 让 dish_id 匹配 shop_id 可以点击跳转到店铺
	for (const item of _shop_dish) {
		let _shop_id = item.shop_id
		let _dish_id = item.dish_id
		for (let i=0; i<result.length; i++) {
			if ("dish_id" in result[i] && result[i].dish_id == _dish_id) {
			result[i].shop_id = _shop_id
			}
		}
	}
	console.log("result_new: ", result)
	return result
}
